package longrise.phone.com.bjjt_henan.main;

import android.content.Context;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.longrise.android.FormParameter;
import com.longrise.android.FrameworkManager;
import com.longrise.android.LFView;

import longrise.phone.com.bjjt_henan.R;
import longrise.phone.com.bjjt_henan.Utils.CommontUtils;

/**
 * 违法类型界面
 */

public class PeccancySelectView extends LFView implements View.OnClickListener {

    private Context mContext;

    private View mView;

    private LinearLayout reverseLLayout;//逆行

    private LinearLayout jumpLLayout;//加塞

    private LinearLayout lineLLayout;//压线

    private LinearLayout lightLLayout;//闯灯

    private LinearLayout stopLLayout;//违停

    public PeccancySelectView(Context context) {
        super(context);
        this.mContext = context;
    }

    @Override
    public FormParameter getFormParameter() {
        FormParameter form = new FormParameter();
        form.setShowtitle(false);
        return form;
    }

    @Override
    public View getView() {
        return mView;
    }

    @Override
    public void init() {
        mView = View.inflate(mContext, R.layout.view_peccancyselect, null);
        //标题栏
        TextView titleTV = (TextView) mView.findViewById(R.id.tv_title);
        titleTV.setText(mContext.getResources().getString(R.string.snapshot));
        mView.findViewById(R.id.hn_btn_back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                OnDestroy();
                closeForm();
            }
        });
        reverseLLayout = (LinearLayout) mView.findViewById(R.id.snapshot_ll_reverse);
        jumpLLayout = (LinearLayout) mView.findViewById(R.id.snapshot_ll_jump);
        lineLLayout = (LinearLayout) mView.findViewById(R.id.snapshot_ll_line);
        lightLLayout = (LinearLayout) mView.findViewById(R.id.snapshot_ll_light);
        stopLLayout = (LinearLayout) mView.findViewById(R.id.snapshot_ll_stop);

        setEvent(true);
    }

    private void setEvent(boolean flag) {
        if (reverseLLayout != null) {
            reverseLLayout.setOnClickListener(flag ? this : null);
        }
        if (jumpLLayout != null) {
            jumpLLayout.setOnClickListener(flag ? this : null);
        }
        if (lineLLayout != null) {
            lineLLayout.setOnClickListener(flag ? this : null);
        }
        if (lightLLayout != null) {
            lightLLayout.setOnClickListener(flag ? this : null);
        }
        if (stopLLayout != null) {
            stopLLayout.setOnClickListener(flag ? this : null);
        }
    }

    @Override
    public void onClick(View v) {
        int type = -1;
        String typeStr = null;
        switch (v.getId()) {
            case R.id.snapshot_ll_reverse:
                type = 0;
                typeStr = CommontUtils.getPeccancyStr("0");
                break;
            case R.id.snapshot_ll_jump:
                type = 1;
                typeStr = CommontUtils.getPeccancyStr("1");
                break;
            case R.id.snapshot_ll_line:
                type = 2;
                typeStr = CommontUtils.getPeccancyStr("2");
                break;
            case R.id.snapshot_ll_light:
                type = 3;
                typeStr = CommontUtils.getPeccancyStr("3");
                break;
            case R.id.snapshot_ll_stop:
                type = 4;
                typeStr = CommontUtils.getPeccancyStr("4");
                break;
            default:
                break;
        }
        if (type != -1) {
            PeccancyReportView view = new PeccancyReportView(mContext, type, typeStr);
            FrameworkManager.getInstance().showNewForm(mContext, view);
        }
    }

    @Override
    public void refresh() {

    }

    @Override
    public void refreshByTime() {

    }

    @Override
    public void OnDestroy() {
        super.OnDestroy();
        setEvent(false);
        mView = null;
    }
}
